<?php

namespace app\api\controller;

use app\common\controller\ApiController;
use app\common\lib\Show;
use think\response\Json;

class User extends ApiController
{
    public function getSelfInfo(): Json
    {
        if(!$this->request->isGet()){
            return Show::error([],'请求方式错误');
        }
        try {
            $data=\app\api\service\User::getUser($this->uid);
        }catch (\Exception $e){
            return Show::error([],$e->getMessage());
        }
        return Show::success($data);
    }
    public function saveUser(): Json
    {
        if(!$this->request->isPost()){
            return Show::error([],'请求方式错误');
        }
        $data=$this->request->post();
        if(empty($data['nick_name'])){
            return Show::error([],'昵称不能为空');
        }
        if(empty($data['avatar_url'])){
            return Show::error([],'头像不能为空');
        }
        try {
            \app\api\service\User::saveUserById($data,$this->uid);
        }catch (\Exception $e){
            return Show::error([],$e->getMessage());
        }
        return Show::success([]);
    }
}